home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / edit / pt20pc.zip / OVERLAY.ASM < prev    next >
Assembly Source File  |  1991-02-04  |  4KB  |  239 lines

  1.  
  2.     TITLE    OVERLAY
  3. ;
  4. ; define all the segments in order
  5. ;
  6. OVERLAY_TEXT    SEGMENT  WORD PUBLIC 'CODE'
  7. OVERLAY_TEXT    ENDS
  8. ;
  9. CONST    SEGMENT  WORD PUBLIC 'CONST'
  10. CONST    ENDS
  11. ;
  12. _BSS    SEGMENT  WORD PUBLIC 'BSS'
  13. _BSS    ENDS
  14. ;
  15. _DATA    SEGMENT  WORD PUBLIC 'DATA'
  16.     extrn    _stktop:word
  17. _DATA    ENDS
  18. ;
  19. DGROUP    GROUP    CONST,    _BSS,    _DATA
  20.     ASSUME  CS: OVERLAY_TEXT, DS: DGROUP, SS: DGROUP, ES: DGROUP
  21. ;
  22. ;**********************************************
  23. ;**********************************************
  24. ; uncomment this to get overlays working again
  25. ;**********************************************
  26. ;    EXTRN    _overlayDriver:FAR
  27. ;**********************************************
  28. ;**********************************************
  29. ;
  30. OVERLAY_TEXT    SEGMENT  WORD PUBLIC 'CODE'
  31. ;
  32.     PUBLIC    _overlay
  33. _overlay PROC    FAR
  34. ;
  35. ; save all the registers on entry
  36. ;
  37.     push    bp
  38.     mov    bp,sp
  39. ;
  40. ; save registers
  41. ;
  42.     mov    cs:oldds,ds
  43.     mov    cs:oldes,es
  44.     mov    cs:oldss,ss
  45. ;
  46. ; set up the interrupt
  47. ;
  48.     mov    ah,25H        ; set interrupt vector
  49.     mov    al,[bp+6]    ; interrupt vector to use
  50.                 ; dx gets offset of the int handler
  51.     mov    dx,OFFSET OVERLAY_TEXT:intProc
  52.     push    ds        ; save ds
  53.     push    cs        ; move cs to ds for set interrupt call
  54.     pop    ds
  55.     int    21H        ; set up the interrupt
  56.     pop    ds        ; restore ds
  57. ;
  58. ; return
  59. ;
  60.     mov    sp,bp
  61.     mov    ax,sp        ; return value
  62.     pop    bp
  63.     ret
  64. ;
  65. _overlay ENDP
  66. ;
  67. ;
  68. ;************************ _criterr *************************
  69. ;
  70.     PUBLIC    _criterr
  71. _criterr PROC    FAR
  72. ;
  73. ; save all the registers on entry
  74. ;
  75.     push    bp
  76.     mov    bp,sp
  77. ;
  78. ; set up the interrupt
  79. ;
  80.     mov    ah,25H        ; set interrupt vector
  81.     mov    al,24H        ; interrupt vector to use
  82.     mov    dx,OFFSET OVERLAY_TEXT:criProc
  83.     push    ds        ; save ds
  84.     push    cs        ; move cs to ds for set interrupt call
  85.     pop    ds
  86.     int    21H        ; set up the interrupt
  87.     pop    ds        ; restore ds
  88. ;
  89. ; return
  90. ;
  91.     mov    sp,bp
  92.     mov    ax,sp        ; return value
  93.     pop    bp
  94.     ret
  95. ;
  96. _criterr ENDP
  97. ;
  98. ;
  99. ;
  100. criProc PROC    FAR
  101. ;
  102.     pop    ax    ; discard DOS IP
  103.     pop    ax    ; discard DOS CS
  104.     pop    ax    ; discard DOS flags
  105.  
  106.     mov    ah,19H    ; stablize DOS with a dummy call to function 19
  107.     int    21H    ;  (get current drive) which cannot cause an error
  108.  
  109.     pop    ax    ; restore application's registers
  110.     pop    bx
  111.     pop    cx
  112.     pop    dx
  113.     pop    si
  114.     pop    di
  115.     pop    bp
  116.     pop    ds
  117.     pop    es
  118.     push    bp    ; set the carry flag (on the stack)
  119.     mov    bp,sp
  120.     or    WORD PTR [bp+6],1
  121.     pop    bp
  122.     mov    ax,97    ; Point-defined error code 97 ==> critical error
  123.     iret
  124. ;
  125. criProc ENDP
  126. ;
  127. ;
  128. ;************************ _getstk *************************
  129. ;
  130. ;
  131.     public    _getstk
  132. _getstk    PROC    far
  133.     mov    dx,ss
  134.     mov    ax,sp
  135.     ret
  136. _getstk    endp
  137.     public    _gethqq
  138.     extrn    STKHQQ:word
  139. _gethqq    PROC    far
  140.     mov    ax,STKHQQ
  141.     ret
  142. _gethqq    endp
  143. ;
  144. ;
  145. ;
  146. oldds        DW    0
  147. oldes        DW    0
  148. oldss        DW    0
  149. ;
  150. ;
  151. myStackPtr    DW    0
  152. savess1        DW    0
  153. savesp1        DW    0
  154. savess2        DW    0
  155. savesp2        DW    0
  156. ;
  157. intProc PROC    FAR
  158. ;
  159. ; save all the registers on entry
  160. ;
  161.     push    ds        ; onto the caller's stack
  162.     mov    ds,cs:oldds    ; restore ds addressability
  163.     cmp    myStackPtr,0    ; determine save stack (ss,sp) area
  164.     je    firstCall    ; this is the first call
  165. secondCall:
  166.     mov    savess2,ss    ; use the second area
  167.     mov    savesp2,sp
  168.     jmp    setupStack
  169. firstCall:
  170.     mov    savess1,ss
  171.     mov    savesp1,sp
  172. ;
  173. ; set up the new stack frame
  174. ;
  175. setupStack:
  176.     inc    myStackPtr
  177.     mov    ss,oldss
  178.     mov    sp,_stktop
  179. ;
  180. ; call the C procedure
  181. ; pass it all the registers
  182. ;
  183. ;
  184.     push    es
  185.     mov    es,oldes
  186.     push    bp
  187.     push    di
  188.     push    si
  189.     push    dx
  190.     push    cx
  191.     push    bx
  192.     push    ax
  193.     sti        ; re-enable interrupts since this may take awhile
  194.             ; we know that no one will make this interrupt call
  195.             ; while we are doing this since this is a software
  196.             ; interrupt
  197. ;**********************************************
  198. ;**********************************************
  199. ; uncomment this to get overlays working again
  200. ;**********************************************
  201. ;    call    FAR PTR _overlayDriver
  202. ;**********************************************
  203. ;**********************************************
  204. ;
  205. ; now restore the registers with their new values
  206. ; this gets the affect of call by value-result
  207. ; disable interrupts while we are changing the stack
  208. ;
  209.     cli
  210.     pop    ax
  211.     pop    bx
  212.     pop    cx
  213.     pop    dx
  214.     pop    si
  215.     pop    di
  216.     pop    bp
  217.     pop    es
  218. ;
  219. ; return
  220. ;
  221.     dec    myStackPtr
  222.     jz    retFirstCall
  223. retSecondCall:
  224.     mov    sp,savesp2
  225.     mov    ss,savess2
  226.     jmp    retAll
  227. retFirstCall:
  228.     mov    sp,savesp1
  229.     mov    ss,savess1
  230.     mov    myStackPtr,0
  231. retAll:
  232.     pop    ds
  233.     iret
  234. ;
  235. intProc ENDP
  236. ;
  237. OVERLAY_TEXT    ENDS
  238. END
  239.